#!/bin/sh
#
# $OpenBSD: pf_states,v 1.1 2010/02/25 17:07:17 sthen Exp $
#
# (c) 2010 Kim H�jgaard-Hansen <kimrhh@gmail.com>
#
# Script to monitor number of pf states from "pfctl -si".
# 
#    ln -s /usr/local/libexec/munin/plugins/pf_states \
#	/etc/munin/plugins/pf_states
#
# ...will monitor number of pf states.
#
# Parameters:
#
# 	config   (required)
# 	autoconf (optional - used by munin-config)
# 	suggest  (optional - used by munin-config)
#
# Magic markers (optional):
#%# family=manual
#%# capabilities=autoconf

if [ "$1" = "autoconf" ]; then
	if [ "$(uname -s)" = "OpenBSD" ]; then
		echo yes
		exit 0
	else
		echo no
		exit 1
	fi
fi

if [ "$1" = "suggest" ]; then
	exit 0
fi

if [ "$1" = "config" ]; then

	echo 'graph_title pf state table size'
	echo 'graph_args --base 1000'
	echo 'graph_category pf'
	echo 'graph_vlabel entries'
	echo 'state.label Entries'
	echo 'state.info Number of state table entries'
	echo 'state.type GAUGE'
	exit 0
fi

pfctl -si | awk '$1=="current" && $2=="entries" { print "state.value " $3 }'
